package unwdmi.app;

import java.util.*;
import java.io.*;
import java.net.*;

import unwdmi.db.*;
import unwdmi.dto.*;
import unwdmi.listener.ClientListener;
import unwdmi.listener.WeatherStationListener;
import unwdmi.connector.*;

/**
 * The main program for the unwdmi weather service server
 * @author Stephan E G Veenstra
 * @author Michel Jansma
 * @version 0.0.1
 */
public class Server {

	public static Database DB_INSTANCE;
	public static String STATION_HOST = "localhost";
	public static int STATION_PORT = 7789;
	public static int CLIENT_PORT = 7790;
	
	private ServerSocket serverStationSocket;
	private ServerSocket serverClientSocket;
	
	private Server(){
		System.out.println("UNWDMI Weather Service Server started");
		try {
			//New Database instance
			Server.DB_INSTANCE = new Database(new DatabaseDTO("localhost", "unwdmi", "root", ""));
			serverStationSocket = new ServerSocket(STATION_PORT);
			serverClientSocket = new ServerSocket(CLIENT_PORT);
			// Create a WeatherStationListener to listen to connecting WeatherStations
			Thread weatherTread = new Thread(new WeatherStationListener(serverStationSocket));
			weatherTread.start();
			// Create a ClientListener
			Thread clientThread = new Thread(new ClientListener(serverClientSocket));
			clientThread.start();
			
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		new Server();
	}

}
